package mushystuff.dtb.core.dao.hibernate;

import java.util.Date;
import java.util.List;

import mushystuff.dtb.core.dao.ProductDAO;
import mushystuff.dtb.core.model.Product;

import org.hibernate.criterion.Expression;
import org.springframework.stereotype.Repository;

@Repository
public final class ProductDAOImpl extends GenericHibernateDAO<Product, Long>
        implements ProductDAO {

    @Override
    public Product persistProduct(Product product) {
        product.setLastModified(new Date());
        product = makePersistent(product);
        log.info("Persisted "  + product);
        return product;
    }

    @Override
    public Product getProduct(long productId) {
        log.info("Getting product with id = " + productId);
        return findById(productId, false);
    }

    @Override
    public List<Product> getAllProducts() {
        log.info("Getting all products ");
        return findAll();
    }
    
    @Override
    public List<Product> getAllActiveProducts() {
        log.info("Getting all active products ");
        return findByCriteria(Expression.eq("active", true));
    }

}
